{include file=header.html}
 <script type="text/javascript" language="javascript" src="{lib file=jquery-1.6.3.min.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=jquery.ui/jquery.ui.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=DatePicker/WdatePicker.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/fabric_info.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery.funkyUI.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=jquery.plugins/jquery.validate_1.11.0.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/select.js}"></script>
<style type="text/css">
.btn-2{margin-bottom:5px;}
.table_no_border,.table_no_border td,.table_no_border th{
	padding:0;
	margin:0;
	border-width:0 1px 0 0;
	}
.fabric_info_list td input,.fabric_info_list td select{width:93%;}
.fabric_info_table td,.fabric_info_table th{
	border-left:none;
	border-bottom:none;
	}
.fabric_info_table th
{
   border-top:none;
}
.tab-display .no_right_border
{
	border-right:none;
}
.fabric_info_table .btn-2{
	line-height:20px;
	height:20px;
	margin-bottom:1px;}
#sample_filesize {width:100px;word-wrap: break-word;word-break: normal;word-break:break-all;}
</style>
<script type="text/javascript">
$(function() {
	 $('#sample_form').validate({
        onkeyup : false,
		onfocusout : false,
        rules : {
			arrival_date: {
				required: true,
				dateISO: true
			},
			brand_id: {
				min: 1
			},
			buyer_id: {
				required: true,
				min: 1
			},
			merchandiser_id: {
				min: 1
			},
			sample_sn: {
				required: true
			},
			ref_sample_style:{
				min: 1
			}
        },
        messages : {
			arrival_date: {
				required: '{$lang.arrival_date_not_empty}',
				dateISO: '{$lang.date_format_error}'
			},
			brand_id: {
				min: '{$lang.brand_select_pls}'
			},
			buyer_id: {
				required: '{$lang.buyer_select_pls}',
				min: '{$lang.buyer_select_pls}'
			},
			merchandiser_id: {
				min: '{$lang.merch_select_pls}'
			},
			sample_sn: {
				required: '{$lang.sample_sn_not_empty}'
			},
			ref_sample_style: {
				min: '{$lang.ref_sample_style_select_pls}'
			}
        }
    });
	
	$('select[select_input="select_input"]').each(function(i) {
		init_select_input($(this));
	});
	$('div.select-input').each(function(i) {
		$(this).css('z-index', $('div.select-input').length - i);
	});
	$('#add_fabric_info').click(function() {
		var tr = $('<tr><th align="right">{$lang.desc}：</th><td class="tab-align-l" colspan="3"></td><th align="right">{$lang.fabric_shop_name}：</th><td class="tab-align-l" colspan="3"></td><td colspan="2" align="left"></td></tr>');
		var sel_input = $($('#fabric_shop_data').html());
		sel_input.attr('select_input', 'select_input');
		sel_input.attr('name', 'new_fabric_info[][fabric_shop_id]');
		sel_input.attr('id', 'new_fabric_info[][fabric_shop_id]');
		sel_input.attr('class', 'input-3');
		var desc = $('<input type="text" class="input-3" name="new_fabric_info[][description]">');
		tr.find('td:eq(0)').append(desc);
		tr.find('td:eq(1)').append(init_select_input(sel_input));
		$('div.select-input').each(function(i) {
			$(this).css('z-index', $('div.select-input').length - i);
		});
		tr.css('background-color', '#F4F8FA');
		var add_fabric_shop = $('#add_fabric_shop');
		tr.insertAfter(add_fabric_shop.parents('tr'));
		if ($('input.btn-2[value="移除"]').length < 1) {
			add_fabric_shop.parent().append($('<input type="button" value="移除" class="btn-2" />'));
		}
		tr.find('td:eq(2)').append($('<input type="button" value="移除" class="btn-2" />'));
		tr.find('td:eq(2)').append(add_fabric_shop);
	//	$('input.btn-2[value="移除"]').click(function() {
	//		remove_fabric_shop($(this));
	//	});
		sort_new_fabric_info();
	});

	$('input[acttype="confirm"]').click(function() {
		if (confirm('是否已经保存信息？更新样板信息之后将会使已确认样板状态无效。\r\n\r\n是否继续？')) {
			$.getJSON('index.php?app=sample&act=confirm&id={$smarty.get.id}', function(json) {
				alert(json.msg);
			});
		}
	});
	
});

function sort_new_fabric_info()
{
	$('input[name^="new_fabric_info"][name$="[description]"]').each(function(i) {
		$(this).attr('name', 'new_fabric_info[' + i + '][description]');
	});
	$('input[name^="new_fabric_info"][name$="[fabric_shop_id]"]').each(function(i) {
		$(this).attr('name', 'new_fabric_info[' + i + '][fabric_shop_id]');
		$(this).attr('id', 'new_fabric_info[' + i + '][fabric_shop_id]');
	});
}

function remove_fabric_shop(_this)
{
	if (!confirm('确定要移除该面料信息吗？')) {
		return;
	}
	$(_this).parent().parent().remove();
}


function check_factory_submit(){

	if(confirm('请仔细检查填写内容是否正确，确认是否提交？')==true){
		var ml_num=0;
		$(".fabric_info_list").each(function(){
				
			if($(this).find("[item='fabric_shop_name']").val()!=0 && $(this).find("[item='item']").val()!=0 && $(this).find("[item='fabric_characteristics']").val()!="")
			{
				ml_num++;
			}
		});
		
		if(ml_num==0)
		{
			alert("请输入面料信息");
			return false;
		}
		
		
	}
	
	return true;
}

function check_desc()
{
	
	if($("#approve_no_desc").val()=="")
	{
		$.funkyUI({url:"index.php?app=sample&act=approve_not_pass",css:{width:"455",height:"330"}});
		return false;
	}
	return true;
}

function re_factory()
{
	
	if($("#return_factory_desc").val()=="")
	{
		
		$.funkyUI({url:"index.php?app=sample&act=return_factory",css:{width:"455",height:"330"}});
		return false;
	}
	return true;
}

function s_dayin(){
	if(confirm('确定要打印此采购单吗?打印此采购单后将不能再更改！')!=true){
		return false;
	}else{
		window.open('{$site_url}/index.php?app=sample&act=print_purchase&id={$smarty.get.id}');
	}
}
</script>
<body>
<div id="fabric_shop_data" style="display:none;"><select><!--{foreach from=$fabricshop_list item=fabric_shop}--><option value="{$fabric_shop.fabric_shop_id}">{$fabric_shop.fabric_shop_name|escape}</option><!--{/foreach}--></select></div>
<div class="sub-body">
      
  <div class="tab-frame" style="width:1050px;">
  <h3 class="tab-title-1"><span>{$lang.sample_more_info}</span></h3>
	<form method="post" id="sample_form" action="{url app=sample&act=$smarty.get.act&id=$smarty.get.id}">
    <table width="100%" cellspacing="0" cellpadding="0" class="tab-display">
    <tr>
      <th style="width:100px;" align="right">{$lang.status}：</th>
      <td class="tab-align-l">{$lang.statuies.$sample.status}</td>
      <th colspan="4">{$lang.front_pic}</th>
		<th colspan="4">{$lang.other_pic}</th>
      </tr>
      <tr>
        <th align="right">{$lang.arrival_date}：</th>
        <td class="tab-align-l"><!-- {if $sample.arrival_date} -->{$sample.arrival_date|date:Y-m-d}<!-- {/if} --></td>
		<td colspan="4" rowspan="9"><img src="{$sample.front_pic}" id="front_pic_show"  width="220" height="264" /><input type="hidden" name="front_pic" id="front_pic" value="" onChange="document.getElementById('front_pic_show').src=this.value;" />
        <input type="hidden" name="front_pic_small" id="front_pic_small" value="" /></td>
		<td colspan="4" rowspan="9"><img src="{$sample.other_pic}" id="other_pic_show"  width="220" height="264" /><input type="hidden" name="other_pic" id="other_pic" value="" onChange="document.getElementById('other_pic_show').src=this.value;" /></td>
      </tr>
      <tr>
        <th align="right">{$lang.sample_sn}：</th>
        <td class="tab-align-l">{$sample.sample_sn|escape}</td>
      </tr>
      <tr>
        <th align="right">{$lang.ref_sample_style}：</th>
        <td class="tab-align-l">
        <!--{foreach from=$lang.ref_sample_styles item=item key=k}-->
            {if $k eq $sample.ref_sample_style}{$item}{/if}
            <!--{/foreach}-->
          </td>
      </tr>
      <tr>
        <th align="right">{$lang.brand_name}：</th>
        <td class="tab-align-l">
        <!--{foreach from=$brand_list item=brand key=k}-->
          {if $brand.brand_id eq $sample.brand_id}{$brand.brand_name}{/if} 
            <!--{/foreach}-->
          </td>
      </tr>

      <tr>
        <th align="right">{$lang.buyer_name}：</th>
        <td class="tab-align-l">
           <!--{foreach from=$buyer_list item=buyer}-->
          {if $buyer.user_id eq $sample.buyer_id}{$buyer.user_name}{/if} 
            <!--{/foreach}-->
          </td>
      </tr>
   
      <tr>
        <th align="right">{$lang.merchandiser}：</th>
        <td class="tab-align-l">        
        <!--{foreach from=$merchandiser_list item=merchandiser}-->
            {if $merchandiser.user_id eq $sample.merchandiser_id}{$merchandiser.user_name}{/if}
            <!--{/foreach}-->
          </td>
      </tr>
      <tr>
        <th align="right">{$lang.style_name}：</th>
        <td class="tab-align-l">
        	<!--{foreach from=$style_list item=style1}-->
            {if $sample.style_id == $style1.style_id}{$style1.style_name|escape}{/if}
			<!--{/foreach}-->
         </td>
      </tr>
      <tr>
       <th align="right">{$lang.factory_name}：</th>
        <td class="tab-align-l">
		  <!--{foreach from=$factory_list item=factory}-->
          {if $sample.factory_id == $factory.factory_id}{$factory.factory_name|escape}{/if}
		  <!--{/foreach}-->
        </td>
      </tr>
      
      <tr>
        <th align="right">{$lang.order_sn}：</th>
        <td class="tab-align-l">
        {$sample.order_sn|escape}
        </td>
      </tr>
      <tr>
        <th colspan="1" align="right" style="font-size:12px;">{$lang.fabric_info}：<br></th>
       <td colspan="12" style="margin:0; padding:0;">
       <table width="100%" class="fabric_info_table" cellpadding="0" cellspacing="0">
       <th width="10%" class="no_left_border">面料描述</th>
       <th width="12%">{$lang.fabric_shop_name}</th>
       <th width="8%">品名/货号</th>
       <th width="8%">颜色</th>
       <th width="6%">数量</th>
       <th width="6%" >价格</th>
       <th width="20%">地址</th>
       <th width="12%">电话</th>
       <th width="6%">凭证</th>
       <th width="6%">色卡</th>
       <!-- {if $user.role==USER_MERCHANDISER} -->
       		<th width="7%" class="no_right_border">操作</th>
       <!-- {/if} -->
       <!-- {if $user.role==USER_MERCHANDISER} -->
       <tr class="fabric_info_list">
       <td>
       <input name="bulk_id[]" type="hidden" value="" />
       <input name="fabric_info_id[]" type="hidden" value="" />
        <input name="cc_id[]" item="cc_id" type="hidden" value="" />
       <input name="description[]" item="description" type="text"  /></td>
       <td align="left">
       <select style="width:95%; height:20px;"  name="fabric_shop_name[]" item="fabric_shop_name" data-placeholder="请选择" class="chzn-select">
       <option value="0" >未选择</option>
      <!--{foreach from=$fabric_shop_list item=fab_shop_info name=fs}-->
		<option value="{$fab_shop_info.fabric_shop_id}"  >{$fab_shop_info.fabric_shop_name}</option>
       <!--{/foreach}-->
       </select>
       </td>    
       <td><select style="width:80px; height:20px;" name="item[]"  item="item" data-placeholder="未选择" >
        <option value="0" >未选择</option>
       </select></td>
       <td><input name="colors[]" item="colors" type="text"  /></td>
       <td><input name="fabric_num[]" item="fabric_num" type="text"  /></td> 
       <td><input name="price[]" item="price" type="text"  /></td>  
       <td><input name="address[]" item="address" type="text"  /></td>
       <td><input name="phone_mob[]" item="phone_mob" type="text"  /></td>
       <td>
       &nbsp;
       </td>
       <td>
       <a item="picture_show" cid=""  style="display:none;" href="javascript:;">查看</a></td>
       <!-- {if $user.role==USER_MERCHANDISER} -->
       		<td class="no_right_border"><input type="button" item="op" class="btn-2" value="添加" pname="sour_add" /></td>
       <!-- {/if} -->
       </tr>
       <!-- {/if} -->
      <!--{foreach from=$fabric_info_list item=fabric_info name=fi}-->
       <tr class="fabric_info_list">
       <td>
       <input name="bulk_id[]" type="hidden" value="{$fabric_info.bulk_id}" />
       <input name="fabric_info_id[]" type="hidden" value="{$fabric_info.fabric_info_id}" />
           <input name="cc_id[]" item="cc_id" type="hidden" value="{$fabric_info.cc_id}" />
       <input name="description[]" item="description" type="text"  value="{$fabric_info.description|escape}" /></td>
       <td>
       <input name="fabric_shop_name[]" item="fabric_shop_name" type="hidden"  value="{$fabric_info.fabric_shop_id}" />
{$fabric_info.fabric_shop_name}</td>    
       <td>
       <input name="item[]" item="item" type="hidden"  value="{$fabric_info.item}" />
{$fabric_info.item}
</td>
       <td>
       <input name="colors[]" item="colors" type="text"  value="{$fabric_info.colors}" /></td>
 		<td>
       <input name="fabric_num[]" item="fabric_num" type="text"  value="{$fabric_info.fabric_num}" /></td>
 		<td>
       <input name="price[]" item="price" type="text"  value="{$fabric_info.price}" /></td>   
       <td>
        <input name="address[]" item="address" type="text"  value="{$fabric_info.address}" /></td>
       <td><input name="phone_mob[]" item="phone_mob" type="text"  value="{$fabric_info.phone_mob}" /></td>
       <td>
       <!-- {if $user.role==USER_SOURCING} -->
      	<a href="{url app=purchase&act=upload_invoices&s_id=$sample.sourcing_id&fid=$fabric_info.fabric_info_id}">上传</a>
      <!-- {else} -->
      	<a href="{url app=purchase&act=upload_invoices&s_id=$sample.sourcing_id&fid=$fabric_info.fabric_info_id}">查看</a>
      <!-- {/if} -->
	</td>
       <td>
      <a  item="picture_show" cid="{$fabric_info.cc_id}"  href="javascript:;">查看</a>
</td>
	<!-- {if $user.role==USER_MERCHANDISER} -->
      		<td class="no_right_border"><input type="button" item="op" class="btn-2" value="移除" onClick="remove_fabric_shop(this);"  /></td>
	<!-- {/if} -->
       </tr>
       <!--{/foreach}-->
  
       </table>
       
       </td>
      </tr>
    </table>
    <div align="center">
    	<!-- {if $user.role==USER_MERCHANDISER || $user.role==USER_SOURCING} -->
    	<span><input type="button" value="打印" class="btn-2" <!-- {if $user.role==USER_SOURCING} -->onclick="javascript:window.open('{$site_url}/index.php?app=sample&act=print_purchase&id={$smarty.get.id}');"<!-- {elseif $user.role==USER_MERCHANDISER} -->onclick="s_dayin()"<!-- {/if} --> /></span>&nbsp;&nbsp;
    	<!-- {/if} -->
    	<!-- {if $user.role==USER_MERCHANDISER} -->
    	<span><input type="submit" name="submit" value="保存" class="btn-2"/></span>&nbsp;&nbsp;
    	<!-- {/if} -->
    </div>
	</form>
  </div>
</div>
<script language="javascript" type="text/javascript" src="{res file=js/tab_color.js}"></script>
</body>
</html>